package com.mj.app.health.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.mj.app.common_util.picasso.ImageLoader;
import com.mj.app.health.MyApplication;
import com.mj.app.health.R;
import com.mj.app.health.activity.ServiceActivity;
import com.mj.app.health.base.BaseFragment;
import com.mj.app.health.defination.IntentKeys;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * ========================================
 * *
 * title: ServiceFragment
 * description:
 * *
 * Created by David Hogan on 2018/3/2.
 * ========================================
 */

public class ServiceFragment extends BaseFragment implements View.OnClickListener{

    @BindView(R.id.s_young)
    ImageView sYoung;
    @BindView(R.id.s_adult)
    ImageView sAdult;
    @BindView(R.id.s_old)
    ImageView sOld;
    @BindView(R.id.sl_young)
    RelativeLayout slYoung;
    @BindView(R.id.sl_adult)
    RelativeLayout slAdult;
    @BindView(R.id.sl_old)
    RelativeLayout slOld;

    @Override
    protected int setLayoutId() {
        return R.layout.fragment_service;
    }

    @Override
    protected void init() {

        initImg((float) 0.35);
        setListener();
    }

    private void setListener() {
        sYoung.setOnClickListener(this);
        sAdult.setOnClickListener(this);
        sOld.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Bundle b = new Bundle();
        switch (v.getId()){
            case R.id.s_young:
                b.putInt(IntentKeys.WEB_FROM, 1);
                break;
            case R.id.s_adult:
                b.putInt(IntentKeys.WEB_FROM, 2);
                break;
            case R.id.s_old:
                b.putInt(IntentKeys.WEB_FROM, 3);
                break;
        }
        toDetail(b);
    }

    private void toDetail(Bundle b){
        redirectTo(ServiceActivity.class, false, b);
        setAnimationIn();
    }

    private void initImg(float height) {

        slYoung.getLayoutParams().height = (int) (MyApplication.getScreenWidth() * height);
        slAdult.getLayoutParams().height = (int) (MyApplication.getScreenWidth() * height);
        slOld.getLayoutParams().height = (int) (MyApplication.getScreenWidth() * height);
        sYoung.getLayoutParams().height = (int) (MyApplication.getScreenWidth() * height);
        sAdult.getLayoutParams().height = (int) (MyApplication.getScreenWidth() * height);
        sOld.getLayoutParams().height = (int) (MyApplication.getScreenWidth() * height);

        ImageLoader.loadWithResId(R.drawable.bg_young, sYoung, R.drawable.bg_young);
        ImageLoader.loadWithResId(R.drawable.bg_adult, sAdult, R.drawable.bg_adult);
        ImageLoader.loadWithResId(R.drawable.bg_old, sOld, R.drawable.bg_old);
    }

}
